/*
 * @Author: xiaosihan 
 * @Date: 2022-05-23 13:53:06 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2023-05-03 02:54:52
 */

import { DoubleSide, Mesh, MeshBasicMaterial, PlaneGeometry, Vector3 } from "three";
import SpriteText from "./SpriteText";


type Props = {
    text?: string;
    textHeight?: number;
    color?: string;
    backgroundColor?: string;
    fontFace?: string;
    fontSize?: number;
    fontWeight?: string;
    padding?: number | [number, number];
    borderWidth?: number;
    borderRadius?: number;
    borderColor?: string;
    strokeWidth?: number;
    strokeColor?: string;
}

export default class PlaneText extends Mesh {

    constructor(text: string = "planeText") {
        super(PlaneText.geometry);
        this.set({ text });
    }

    type = "PlaneText";

    static geometry = new PlaneGeometry(1, 1, 1, 1);

    spriteText = new SpriteText("");

    material = new MeshBasicMaterial({ transparent: true, side: DoubleSide, map: this.spriteText.material.map });

    set(parame: Props) {
        for (let key in parame) {
            //@ts-ignore
            this.spriteText[key] = parame[key];
        }

        this.scale.copy(this.spriteText.scale);
        this.scale.max(new Vector3(1, 1, 1));
        this.material.map = this.spriteText.material.map;
    }

    get(prop: keyof SpriteText) {
        return this.spriteText[prop];
    }

}
